<{if $page_goodslink}>
<div class="mod">
<h3><{t}>相关商品<{/t}></h3>
  <div class="mod-content">

    <div class="product-related-content">
      <div class="related-items-wrap">
        <{foreach from=$page_goodslink.link key=key item=row}>
        <div class="goods-item related-item-wrap">
		<div class="item">
		<input type="hidden" name="goods[goods_id]" value="<{$row.goods_id}>">
		<input type="hidden" name="goods[product_id]" value="<{$row.product_id}>">
        <a href="<{link app=b2c ctl=site_product arg0=$row.product_id}>" class="item-img-link"><img data-src="<{$row.image_default_id|default:$imageDefault|storager:'s'}>" alt="<{$row.name}>" title="<{$row.name}>" class="lazyOwl"></a>
          <div class="goods-info product-buy" style="margin:0px;">
            <div class="item-title"><a href="<{link app=b2c ctl=site_product arg0=$row.product_id}>"><{$row.name}></a></div>
            <p>
			  <{include file='site/product/info/gl_props.html'}>
			</p>
			<!--<p><del><{t}>原价：<{/t}><{$row.mktprice|cur}></del> <{$row.s_price|cur}></p>-->
			<!--商品库存-->
            <{include file='site/product/info/gl_store.html'}>
			<{if $row.store>0}>
				<a class="btn btn-primary btn-block" style="margin-top:15px;" href="<{link app=b2c ctl=site_cart act=add arg0=goods arg1=$row.goods_id arg2=$row.product_id arg3=1}>" target="_dialog_minicart">
				<i class="icon icon-cart"></i><{t}>加入购物车<{/t}></a>
			<{else}>
				<a class="btn btn-primary btn-block"  href="javascript:void(0);">
				<{t}>已售罄<{/t}></a>
			<{/if}>
          </div>
		 </div> 
        </div>
        <{/foreach}>
      </div>
    </div>

  </div>
</div>

<script type="text/javascript">

	jQuery('.related-items-wrap').owlCarousel({
       items:4,
	  // itemsDesktop:[1600,5],
	 itemsDesktopSmall: [1200,3],
	   itemsTablet: [768,2],
		itemsMobile: [479,1],
        loop:true,
		navigation:true,
		navigationText:['<span class="glyphicon glyphicon-chevron-left"></span>','<span class="glyphicon glyphicon-chevron-right"></span>'],
		pagination: false,
		paginationNumbers: false,
		nav: false,
        dots: false,
		autoWidth: true,
		autoPlay : 5000,
		stopOnHover : true,
		lazyLoad : true
    });

//以下相关商品
/*(function (){
    //计算中间区域宽度及item边距，并用于切换
    var cols;
    var section = $('product_section');//整个大DIV
    var autoArea = $('product_related');//相关商品div
    if(!autoArea) return;
    var group = autoArea.getElement('.product-related-content');//主要内容
    var groupWidth = section.getSize().x-section.getPatch('padding','border').x - group.getPatch().x;
    var item = group.getElement('.goods-item');
    var itemWidth = item.measure(function(){
        return this.getSize().x + this.getPatch('margin').x;
    });
    cols = (groupWidth / itemWidth).toInt();
    groupWidth = cols * itemWidth;
    group.setStyles({'margin':'0 auto','width': groupWidth});

    new Switchable(autoArea, {
        haslrbtn:true,
        autoplay: false,
        viewSize: [groupWidth],
        circular: false,
        disableCls: 'over',
        steps: cols,
        hasTriggers:false,
        position: '',
        effect: 'scrollx',
        onInit: function() {
            if(this.content[0].getStyle('width').toInt() <= groupWidth) {
                this.prevbtn.setStyle('visibility', 'hidden');
                this.nextbtn.setStyle('visibility', 'hidden');
                autoArea.setStyle('width', section.getSize().x - section.getPatch('padding', 'border').x - autoArea.getPatch().x);
            }
        }
    });
})();*/

//== 为相关商品数量选择框绑定事件 by yyj 2015/10/22
function bindQuantityEvent(elements, callback) {
	elements = document.id(elements) || $$(elements);
	if(!elements || !elements.length) return;
	var value = '';
	elements.addEvents({
		//= 数量按钮
		'click:relay(.btn-gl-decrease,.btn-gl-increase)': function(e) {
			var input = this.getParent().getElement('input');
			value = +input.value;
			input.value = this.hasClass('btn-gl-decrease') ? value - 1 : value + 1;
			callback && callback(input, value);
		},
		//= 数量输入框
		'focus:relay(input)': function(e){
			value = +this.value;
		},
		'change:relay(input)': function(e) {
			callback && callback(this, value);
		}
	});
}
bindQuantityEvent('.p-quantity', setQuantity);

//获取相关商品数量值 by yyj 2015/10/22
function getQuantity(el, type) {
    return el.getElement('input[name=' + type + ']').value;
}

//设置相关商品数量 by yyj 2015/10/22
function setQuantity(input, value) {
    var type = 'product';
    var p = input.getParent('li');
    inputCheck(input, {min: input.get('min'), max: input.get('max'), 'default': value, store: getQuantity(p, 'gl_stock')});
}

//== 商品数量输入框正确性检测 by yyj 2015/10/22
function inputCheck(input, options) {
    if(!input) return false;
    options = options || {};
    if(isNaN(options.min)) options.min = 1;
    if(isNaN(options.max)) options.max = 999999;
    options['default'] = options['default'] || options.min;
    var value = +input.value;
    var tips = new Tips(input);
    var pre = '';
    var msg = '';
    if(options.store && options.store - value <= 0) {
        pre = '<{t}>库存有限，<{/t}>';
    }
    if(value < options.min) {
        input.value = options.min;
        msg = '<{t}>此商品的最小购买数量为<{/t}>' + options.min + '<{t}>件<{/t}>';
    }
    else if(value > options.max){
        input.value = options.max;
        msg = pre + '<{t}>此商品最多只能购买<{/t}>' + options.max + '<{t}>件<{/t}>';
    }
    else if(isNaN(value)) {
        input.value = options['default'];
        msg = '<{t}>只允许输入数字<{/t}>';
    }
    if (msg) {
        tips.show(msg);
        return false;
    }
    tips.hide();
    if(options.callback) options.callback(input, options['default']);
    return true;
}

window.addEvent('domready',function(){
    miniCart.init();
});
</script>
<{/if}>
